/**
 * Created by Meathill on 2017/7/8.
 */

// 案例页面里面需要一个小脚本
let portfolio = $('#portfolio-slide');
if (portfolio.length) {
  if (document.body.clientWidth > 576) {
    portfolio
      .on('mouseover', '.card', function () {
        portfolio.find('.active').removeClass('active');
        let index = $(this).addClass('active').index();
        $('#portfolio-slide').find('.indicator').eq(index).addClass('active');
      })
      .on('mouseover', '.indicator', function () {
        portfolio.find('.active').removeClass('active');
        let index = $(this).addClass('active').index();
        $('#portfolio-slide').find('.card').eq(index).addClass('active');
      });
    portfolio.find('.card').eq(1).addClass('active');
    portfolio.find('.indicator').eq(1).addClass('active');
  } else {
    portfolio.find('.card').eq(0).addClass('active');
    portfolio.find('.indicator').eq(0).addClass('active');
    portfolio.find('.scroll').on('scroll', function () {
      let offset = 520 - document.body.clientWidth;
      let index = 0;
      while (this.scrollLeft > index * 260 + offset) {
        index++;
      }
      portfolio.find('.card').removeClass('active')
        .eq(index).addClass('active');
      portfolio.find('.indicator').removeClass('active')
        .eq(index).addClass('active');
    });
  }
}

// lazyload
$('.lazy').lazyload({
  threshold : 500,
  effect : "fadeIn"
});

// 这些东西晚点执行应该没问题
setTimeout(function () {
  // 安全认证
  let _kxs = document.createElement('script');
  _kxs.id = 'kx_script';
  _kxs.async = true;
  _kxs.setAttribute('cid', 'kx_verify');
  _kxs.src = ('https:' === document.location.protocol ? 'https://ss.knet.cn' : 'http://rr.knet.cn') + '/static/js/icon3.js?sn=e170106420100661546vb6000000&tp=icon3';
  _kxs.setAttribute('size', 0);
  let _kx = document.getElementById('kx_verify');
  _kx.parentNode.insertBefore(_kxs, _kx);

  // 把最后工商的标记挪到前面去
  $('#wuhan-gs').append($('script.gs + div'));
}, 1000);

// 监测代码
window._hmt = window._hmt || [];
(function() {
  let hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?eb45199dd49660849d61df29e6af6751";
  let s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(hm, s);
})();